﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using STX.Repository;
using STX.Service;

namespace STX.Admin.Export
{
    public partial class FinanceYear_HDMX : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                for (DateTime dt = DateTime.Now; dt >= DateTime.Now.AddYears(-10); dt = dt.AddYears(-1))
                {
                    this.DropDownList1.Items.Add(new ListItem(dt.Year.ToString(), dt.Year.ToString()));
                }
                GenerateReport(DateTime.Now.Year);
            }
        }

        private void GenerateReport(int year)
        {
            this.ReportViewer1.LocalReport.ReportPath
                = Server.MapPath("~/Administrator/Export/ReportViewerTemplates/FinanceYear_HDMX.rdlc");

            BizActivityService BizActivityService = new BizActivityService();
            BizActivityService.Transaction = new EfTransactionContext();
            ReportDataSource dataSource = new ReportDataSource("DataSet1", BizActivityService.GetHdmxByYear(year));
            ReportParameter rp = new ReportParameter("ReportYear", (year).ToString());
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { rp });

            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.DataSources.Add(dataSource);
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
        }

        protected void btnGenerate(object sender, EventArgs e)
        {
            int year = DateTime.Now.Year;
            int.TryParse(this.DropDownList1.SelectedValue, out year);
            GenerateReport(year);
        }
    }
}